package com.kk.knife4j.config;

import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * the type of springboot-knife4j
 *
 * <p>
 * .
 *
 * @author 王志强
 * @date 2022-11-08
 */
@Configuration
@EnableSwagger2
public class Knife4jConfig {

    private final OpenApiExtensionResolver openApiExtensionResolver;

    @Autowired
    public Knife4jConfig(OpenApiExtensionResolver openApiExtensionResolver) {
        this.openApiExtensionResolver = openApiExtensionResolver;
    }

    @Bean("defaultApi1")
    public Docket defaultApi1() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(new ApiInfoBuilder()
                        .title("这是标题")
                        .description("这里写描述")
                        .termsOfServiceUrl("http://www.xx.com/")
                        .contact(new Contact("little_lunatic", "https://knife.blog.csdn.net", "446783737@qq.com"))
                        .version("1.0.0")
                        .build())
                .host("https://www.baidu.com")
                //分组名称
                .groupName("5.2.0")
                .select()
                //指定Controller扫描路径。可以不具体到controller，它会扫描指定路径下的所有
                .apis(RequestHandlerSelectors.basePackage("com.kk"))
                .paths(PathSelectors.any())
                .build()
                .extensions(openApiExtensionResolver.buildExtensions("5.2.0"));
    }

    @Bean("defaultApi2")
    public Docket defaultApi2() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(new ApiInfoBuilder()
                        .title("这是标题")
                        .description("这里写描述")
                        .termsOfServiceUrl("http://www.xx.com/")
                        .contact(new Contact("little_lunatic", "https://knife.blog.csdn.net", "446783737@qq.com"))
                        .version("1.0.0")
                        .build())
                .host("https://www.baidu.com")
                //分组名称
                .groupName("5.2.1")
                .select()
                //指定Controller扫描路径。可以不具体到controller，它会扫描指定路径下的所有
                .apis(RequestHandlerSelectors.basePackage("com.kk"))
                .paths(PathSelectors.any())
                .build()
                .extensions(openApiExtensionResolver.buildExtensions("5.2.1"));
    }
}
